<?php

/**
 * Description of addJournalThesis
 *
 * @author Runner
 */

class addJournalThesisInfo extends AddInformation{
    private $journalThesis;
    private $queryStr;
    
    function __construct($journalThesis=null) {
        $this->journalThesis = $journalThesis;
        $this->queryStr = sprintf('insert into JournalThesis(name, ownerAuthor, responsibleAuthor, volume,'
                                        . ' journalName, issue, year, searchType, searchID, influenceFactor, recommendLevel, '
                                        . ' auditingState)'.
                                        'values("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")', 
                                        $this->journalThesis->name, $this->journalThesis->ownerAuthor,
                                        $this->journalThesis->responsibleAuthor, $this->journalThesis->volume,
                                        $this->journalThesis->journalName, $this->journalThesis->issue, $this->journalThesis->year,
                                        $this->journalThesis->searchType, $this->journalThesis->searchID,
                                        $this->journalThesis->influenceFactor, $this->journalThesis->recommendLevel,
                                        $this->journalThesis->auditingState
                                    );
        
    }
    
    public function add($linkIdentify) {
        if($this->check()){
            if($this->addInfo($this->queryStr, $linkIdentify)){
                return true;
            }
            return false;
        }
    }
    
    /* 检查数据是否合格 */
    function check(){
        if($this->journalThesis==NULL){
            return false;
        }
        /* 检查是否为空字符串 */
        foreach (AttributesName::$journalThesis as $value) {
            if($this->journalThesis->$value==""){
                return false;
            }
        }
        /* 检查是否符合字符串要求 */
        /* 匹配日期 */
       $timePattern = '/[0-9]{4}/';       // 日期的正则表达式模式
       if( preg_match($timePattern, $this->journalThesis->year)==0 ){
           return false;
       }
        return true;
    }
}
